/*
 * @Description: 封装wx的网络请求
 * @Author: pinus
 * @Email: pinus0716@163.com
 * @Git: https://gitee.com/xyf97
 * @Date: 2021-10-21 21:06:21
 * @LastEditTime: 2021-10-28 21:05:21
 */
export default (url, data = {}, method = 'GET') => {
  return new Promise((resolve, reject) => {
    wx.request({
      url: 'http://localhost:4000' + url,
      data,
      method,
      header: {
        cookie: wx.getStorageSync('cookies') ? wx.getStorageSync('cookies').find(item => item.indexOf('MUSIC_U') !== -1) : ''
      },
      success: res => {
        // console.log(res)
        if (data.isLogin) {
          wx.setStorageSync('cookies', res.cookies)
        }
        resolve(res.data)
      },
      fail: res => {
        reject(res)
      }
    })
  })
}
